using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class Controls_ServiceSelect : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    private string mServiceIdHiddenField;

    public string ServiceIdHiddenField
    {
        get
        {
            Control ctrl = Parent.FindControl(mServiceIdHiddenField);
            if (ctrl != null)
            {
                return ctrl.ClientID;
            }
            return string.Empty;
        }
        set
        {
            mServiceIdHiddenField = value;
        }
    }

    private string mServiceTextBox;

    public string ServiceTextBox
    {
        get
        {
            Control ctrl = Parent.FindControl(mServiceTextBox);
            if (ctrl != null)
            {
                return ctrl.ClientID;
            }
            return string.Empty;
        }
        set
        {
            mServiceTextBox = value;
        }
    }

    private string mPriceBgTextBoxId;

    public string PriceBgTextBoxId
    {
        get
        {
            Control ctrl = Parent.FindControl(mPriceBgTextBoxId);
            if (ctrl != null)
            {
                return ctrl.ClientID;
            }
            return string.Empty;
        }
        set
        {
            mPriceBgTextBoxId = value;
        }
    }
    public string GetFunctionCallString(object serviceId, object serviceNameBg, 
        object serviceNameEn, object servicePriceBg )
    {
        string functionCallString = string.Format("UpdateServiceFields('{0}', '{1}', '{2}', '{3}')", serviceId,
            serviceNameBg, serviceNameEn, servicePriceBg);
        return functionCallString;
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string serviceNameBg = tbServiceNameBg.Text;
        string serviceNameEn = tbServiceNameEn.Text;

        StringBuilder filterExpression = new StringBuilder();

        bool filterIsEmpty = true;
        if (serviceNameBg != string.Empty)
        {
            filterExpression.Append(string.Format("NameBG=" + "'{0}'", serviceNameBg));
            filterIsEmpty = false;
        }

        if (serviceNameEn != string.Empty)
        {
            if (!filterIsEmpty)
            {
                filterExpression.Append(" AND ");
            }
            filterExpression.Append(string.Format("NameEN=" + "'{0}'", serviceNameEn));
            filterIsEmpty = false;
        }

        if (filterExpression.Length > 0)
        {
            odsServices.FilterExpression = filterExpression.ToString();
        }
        gvServices.SelectedIndex = -1;
        gvServices.DataBind();
    }

    protected void gvServices_Sorting(object sender, GridViewSortEventArgs e)
    {
        gvServices.SelectedIndex = -1;
    }
}
